﻿@using System.Web.Optimization
@inherits VocaDb.Web.Code.VocaDbPage<VocaDb.Model.DataContracts.Tags.TagBaseContract>

@{
	PageProperties.Title = "Merge tag - " + Model.Name;
	ViewBag.Parents = new[] {
		Html.ActionLink("Tags", "Index", "Tag"),
		Html.ActionLink(Model.Name, "DetailsById", new { id = Model.Id, slug = Model.UrlSlug }),
		Html.ActionLink("Edit", "Edit", new { id = Model.Id }),
	};

}

@using (Html.BeginForm()) {

	@Helpers.MergeEntryInfo()

	<input type="hidden" name="targetTagId" id="targetTagId" data-bind="value: target.id" />

	<br />
	<div class="clearfix">
		<div class="pull-left">
			@KnockoutHelpers.LockingAutoComplete("tagAutoComplete", "target.entry", "target.name", "target.id", extraBindings: "tagFilter: tagFilter")
		</div>
		<div class="pull-left entry-field-inline-warning">
			<div class="alert" data-bind="visible: validationError_targetIsNewer" style="display: none;">
				<span class="icon-line errorIcon"></span>
				@ViewRes.EntryMergeStrings.ValidationErrorTargetIsNewer
			</div>

			<div class="alert" data-bind="visible: validationError_targetIsLessComplete" style="display: none;">
				<span class="icon-line errorIcon"></span>
				@ViewRes.EntryMergeStrings.ValidationErrorTargetIsLessComplete
			</div>
		</div>
	</div>

	<br />

	<button type="submit" class="btn btn-primary" id="mergeBtn" data-bind="enable: target.id">@ViewRes.EntryMergeStrings.MergeBtnText</button>

}

@section BodyScripts {
	@Scripts.Render("~/bundles/shared/edit", "~/bundles/Tag/Merge")
	<script type="text/javascript">

		$(function () {

			var repo = new vdb.repositories.TagRepository('@RootPath');
			var data = @ToJS(Model);
			var vm = new vdb.viewModels.tags.TagMergeViewModel(repo, data);
			ko.applyBindings(vm);

			$("#mergeBtn").click(function () {
				return confirm("Are you sure you want to merge the tags?");
			});

	    });

	</script>
}